<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="ntModalLabel" type="{$request}">{:strtoupper($title)}</h4>
</div>
<div class="modal-body">
        <div class="row clearfix">
                <div class="col-md-12 column">
                    <div class="alert alert-dismissable alert-info">
                    <button type="button" class="close">×</button>
                    <p></p>
                    </div>
                </div>
            </div>
    <div class="row clearfix">
        <div class="col-md-8">
            <table class="table table-striped ntTable">
                <tbody>
                    <tr>
                        <td>{:strtoupper(lang("product_information"))}</td>
                        <td>
                            
                            {if isset($productList)}
                                {foreach $productList as $k=>$v}
                                    <small>{$v.id} / {$v.brand_name}</small><br />
                                    {$v.pro_name}
                                {/foreach}
                                <input type="hidden" id="pro_id" value="{$v.id}">
                            {else /}
                                <input type="hidden" id="pro_id" value="0">
                            {/if}
                        </td>
                    </tr>
                    <tr>
                        <td>{:strtoupper(lang('upload_image'))}</td>
                        <td>
                            <div class="input-group">
                                <input type="text" class="form-control">
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-primary up-img">
                                        <span class="fa fa-file-upload"> </span> {:strtoupper(lang('upload_product_image'))}
                                    </button>
                                    <input type="file" id="inName" name="files[]"   style="opacity: 0">
                                </span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>{:strtoupper(lang('whether_to_icon'))}</td>
                        <td>
                            <label class="radio-inline">
                                <input type="radio" name="is_icon" value="1" {if isset($imgInfo.is_icon)}{if condition="$imgInfo.is_icon eq 1" } checked {/if}{/if}> {:strtoupper(lang('yes'))}
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="is_icon" value="2" {if isset($imgInfo.is_icon)}{if condition="$imgInfo.is_icon eq 2" } checked {/if} {else /} checked {/if}> {:strtoupper(lang('no'))}
                            </label>
                        </td>
                    </tr>
                    <tr id="select_prochar">
                        <td>{:strtoupper(lang("the_role_of_product"))}</td>
                        <td>
                            <select class="form-control" id="prochar_id">
                                <option value="0">{:strtoupper(lang('product'))} {:strtoupper(lang('image'))}</option>
                                {if isset($procharlist)}
                                    {foreach $procharlist as $k1=>$v1}
                                    <option value="{$v1.id}" {if isset($prochar_id)}{if condition="$prochar_id == $v1.id"}selected{/if}{/if}>{$v1.content}</option>
                                    {/foreach}
                                {/if}
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="col-md-4 text-center">
            {notempty name="$imgInfo"}
                    <img src="{$imgInfo.img_url}" class="preview" id="img_id" img_id="{$imgInfo.id}" border="0" width="256px" height="256px">
            {else /}
                <img id="editimg" src="" class="preview" border="0" style="display: none;" width="256px" height="256px">
            {/notempty}
        </div>
    </div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>{:strtoupper(lang('cancel'))}</button>
<button type="button" class="btn btn-primary savefun" style="padding-left:24px;padding-right:24px"><span class="glyphicon glyphicon-ok"></span>{:strtoupper(lang('confirm'))}</button>
</div>
<script>
var read = new FileReader()
$('.up-img').click(function(){
$('#inName').click()
})
var filearr=[]
$('#inName').change(function(){
    $('#editimg').show()
    var imgurl=$(this).val().replace(this.files[0].name,"")
    filearr[0]=this.files[0]
    $('.preview').attr('src',URL.createObjectURL(filearr[0]))
})
$('.savefun').click(function(){
    if($('#ntModalLabel').attr('type') == 'add'){
        var url ="/admin/product/proAddNewJump_imgAdd?request=insert";
    }else if($('#ntModalLabel').attr('type') == 'edit'){
        var url ="/admin/product/proAddnew_imgedit?request=update";
    }
    var formData = new FormData();
    formData.append('pro_id',$('#pro_id').val());
    formData.append('is_icon',$('input[name="is_icon"]:checked').val());
    formData.append('prochar_id',$('#prochar_id option:selected').val());
    formData.append('img_id',$('#img_id').attr('img_id'));
    for (var i = 0; i < filearr.length; i++) {
        formData.append("file["+i+"]", filearr[i]);
    }
    $.ajax({
        url:'/admin/product/imgUpdate',
        type:'POST',
        data:formData,
        cache: false,
        contentType: false,    //不可缺
        processData: false,    //不可缺
        success:function(data){
            data = JSON.parse(data)
            if(data.status==1 || data == true){
                change_mes_type('.alert',data.status)
                $('.alert').show()
                $('.alert p').html('*'+data.msg+'<br>')
                $('#proimg_editModal').modal('hide')
            }else{
                change_mes_type('.modal-body .alert',data.status)
                $('.modal-body .alert').show()
                $('.modal-body .alert p').html('*'+data.msg+'<br>')
            }
        }
    });
})
</script>
